home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 6 code / Threads / Threads Package 2.0d17 / !! Threads Update v. 2.0d17 next >
Encoding:
Text File  |  1991-10-10  |  4.4 KB  |  72 lines  |  [TEXT/ttxt]

  1. Additions to the Threads Package:
  2.  
  3. A few new features have been added to the Threads package since it appeared in issue 7 of Develop.  The main enhancement is the ability to create an application that uses the Threads and Futures package, but does not depend on the Threads INIT.
  4.  
  5. The new version of the Threads package will attempt to load the Threads INIT if it was not present in the System folder when the machine started up.   Use ResEdit to copy 'INIT' resource 1 and 'CODE' resource 30217 from the Threads INIT, and paste them into the resource fork of your application.  If the Threads INIT has not been loaded when your application calls InitThreads, the threads package will be loaded into the system heap automatically.
  6.  
  7.     pascal OSErr InitThreads( short threadFlags )
  8.  
  9. The call to InitThreads is more or less the same as it was presented in Develop 7; it is still possible to pass 'true' or 'false' to InitThreads, and doing so will cause the threads package to behave the same way it was documented in that issue.  There are other values that may be provided, though: 
  10.  
  11.     kUsesFPU
  12.     kMainThreadHasPriority
  13.     kDreamEveryTick
  14.  
  15. kUsesFPU specifies whether or not the threads package should save the floating point registers on context switches.
  16.  
  17. Specifying kMainThreadHasPriority  will cause the threads package to swap in the main thread whenever events are pending, even if there are other threads that have not had a chance to run.
  18.  
  19. The flag kDreamEveryTick, if specified, will cause the threads package to call the 'LetThreadsDream' procedure periodically.  Threads are given time to dream when Yield is called if they have not dreamed within the last tick (1/60th of a second).  If the kDreamEveryTick flag is not specified, threads will not dream unless your application explicitly calls 'LetThreadsDream'.
  20.  
  21.     pascal OSErr SleepForNTicks(ThreadHandle theThread,
  22.                     long sleepTime)
  23.  
  24. SleepForNTicks puts the thread to sleep, but it also installs a dream procedure that will wake the thread up once the  specified sleep time has elapsed.  If your application has installed a dreaming procedure, it will also be called while the thread sleeps.
  25.  
  26.     pascal void ThreadEach( ThreadIterProc proc, void* refCon )
  27.  
  28. ThreadEach calls the specified ThreadIterProc once for every thread that is active in the system.  The function prototype for a ThreadIterProc is:
  29.  
  30.     typedef pascal Boolean (*ThreadIterProc)(ThreadHandle, void*);
  31.  
  32. The parameters for this function are a ThreadHandle and the refcon that was supplied to the ThreadEach function.
  33.  
  34.     pascal OSErr RegisterContextGlobal( long* theGlobal )
  35.  
  36. RegisterContextGlobal installs a special custom swapping routine that saves and restores the specified long integer (or pointer) every time a thread swaps in or swaps out.  Most custom swapping procedures didn't do anything other than swap a few pointers, so RegisterContextGlobal was provided to greatly simplify applications in this situation.  Any number of globals may be registered with this routine; none of the thread's fUserBytes are used to save or restore the globals registered.
  37.  
  38. RegisterContextGlobal must be called at the beginning of your application, before any new threads have been started.
  39.  
  40.     pascal Boolean InMainThread()
  41.  
  42. InMainThread returns 'true' if the current thread is the main thread.
  43.  
  44.     pascal ThreadHandle GetMainThread()
  45.  
  46. GetMainThread returns the ThreadHandle of the main thread.
  47.  
  48.     pascal ThreadProc InstallSwapProc( long selector,
  49.                     ThreadProc newSwap )
  50.  
  51. InstallSwapProc installs a customized swapping procedure, and returns a function pointer to the old swapping routine.  It is still permissible to set up custom swapping procedures as described in Develop issue 7.
  52.  
  53. The valid selectors for InstallSwapProc are:
  54.  
  55.     kCopyContextSel
  56.     kSwapInSel
  57.     kSwapOutSel
  58.     kFreeThreadSel
  59.     kScheduleSel
  60.     kPreYieldSel
  61.     kPostYieldSel
  62.  
  63. The selectors kCopyContextSel, kSwapInSel, kSwapOutSel, kFreeThreadSel and kScheduleSel are described in Develop issue 7.  kPreYieldSel specifies a routine that is called at the beginning of every Yield() instruction, and kPostYieldSel is called at the end of every Yield().  It is not likely that you will need to install a pre-yield or post-yield swapping procedure; usually, you should override CopyContext and SwapIn.
  64.  
  65. Note:  the schedule procedure is actually a SceduleProc, not a ThreadProc.  The prototypes for these function pointers are:
  66.  
  67.     typedef pascal OSErr (*ThreadProc)(ThreadHandle);
  68.  
  69.     typedef pascal ThreadHandle (*ScheduleProc)(ThreadHandle);
  70.  
  71.  
  72.